<?php

$db_name =  "vrwebmonitor";
$dbcnx = @mysql_connect("localhost","root","060416");
	if (!$dbcnx) 
	{
		echo "ÎÞ·¨Á¬½ÓÊý¾Ý¿â£¬ÇëÉÔºóÔÙÊÔ!<br>";
		echo '<p><a href="1.html">·µ»ØµÇÂ½½çÃæ</a>';
		exit();
	} 

	if (!@mysql_select_db("$db_name", $dbcnx) ) 
	{
		echo "ÎÞ·¨Á¬½ÓÊý¾Ý¿â£¬ÇëÉÔºóÔÙÊÔ!<br>";
		echo '<p><a href="1.html">·µ»ØµÇÂ½½çÃæ</a>';
		exit();
	} 
//if ( ($pwd==$password) && (($permitflag==1)||($permitflag==2)) || $_GET["fr"] == "ajax" )

	//$db_name =  "vrwebmonitor";
	$xml_data = "";//"<?xml version=\"1.0\" encoding=\"UTF-8\"?..>\n";
	$xml_data .= "<topology>\n";
	//echo $xml_data."<br />";


	$table_name = "vrlinkstate";
	$exec = "SELECT * FROM $table_name;";
	$vlink_result = mysql_query($exec);
	$vlink_xml;
	while ($row=mysql_fetch_array($vlink_result))
	{
		$tmp_xml .= "\t\t<vlink>\n";
		$tmp_xml .= "\t\t\t<vlinkid>" . $row["vlinkid"] . "</vlinkid>\n";
		$tmp_xml .= "\t\t\t<oppipv6>" . $row["oppipv6"] . "</oppipv6>\n";
		$tmp_xml .= "\t\t\t<locipv4>" . $row["locipv4"] . "</locipv4>\n";
		$tmp_xml .= "\t\t\t<oppipv4>" . $row["oppipv4"] . "</oppipv4>\n";
		$tmp_xml .= "\t\t\t<linkstate>" . $row["linkstate"] . "</linkstate>\n";
		$tmp_xml .= "\t\t\t<gohops>" . $row["gohops"] . "</gohops>\n";
		$tmp_xml .= "\t\t\t<comehops>" . $row["comehops"] . "</comehops>\n";
		$tmp_xml .= "\t\t\t<rtt>" . $row["rtt"] . "</rtt>\n";
		$tmp_xml .= "\t\t\t<sendinterval>" . $row["sendinterval"] . "</sendinterval>\n";
		$tmp_xml .= "\t\t</vlink>\n";
		$vlink_xml[$row["vraddr"]][$row["locipv4"]] = $tmp_xml;
		$tmp_xml = "";
	}
	//echo "<pre>";
	//var_dump($vlink_xml);
	//echo "</pre>";
	
	$table_name = "vrlist";
	$exec = "SELECT * FROM $table_name;";
	$vr_result = mysql_query($exec);

	while($record=mysql_fetch_array($vr_result))
	{
		$xml_data .= "\t<vr>\n";
		$xml_data .= "\t\t<vraddr>" . $record["vraddr"] . "</vraddr>\n";
		$xml_data .= "\t\t<port>" . $record["port"] . "</port>\n";
		$xml_data .= "\t\t<numofvlink>" . $record["numofvlink"] . "</numofvlink>\n";
		$xml_data .= "\t\t<linkstate>" . $record["linkstate"] . "</linkstate>\n";
		foreach ( $vlink_xml[$record["vraddr"]] as $value )
		{
			$xml_data .= $value;
		}
		$xml_data .= "\t</vr>\n";
	}
	$xml_data .= "</topology>\n";
	echo $xml_data;

?>

